home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-05-01 | 5.2 KB | 265 lines | [TEXT/MPS ] |
- // UProjFileHandler.cp
- // Copyright © 1984-1991 by Apple Computer Inc. All rights reserved.
-
-
- #ifndef __ALIASES__
- #include <Aliases.h>
- #endif
-
- #ifndef __UFILE__
- #include <UFile.h>
- #endif
-
- #ifndef __EDITIONS__
- #include <Editions.h>
- #endif
-
- #ifndef __APPLEEVENTS__
- #include <AppleEvents.h>
- #endif
-
- #ifndef __ULIST__
- #include <UList.h>
- #endif
-
- #ifndef __UEVENT__
- #include <UEvent.h>
- #endif
-
- #ifndef __UCOMMAND__
- #include <UCommand.h>
- #endif
-
- #ifndef __UEVTHANDLER__
- #include <UEvtHandler.h>
- #endif
-
- #ifndef __DIALOGS__
- #include <Dialogs.h>
- #endif
-
- #ifndef __UAPPLICATION__
- #include <UApplication.h>
- #endif
-
- #ifndef __UDOCUMENT__
- #include <UDocument.h>
- #endif
-
- #ifndef __UFILEBASEDDOCUMENT__
- #include <UFileBasedDocument.h>
- #endif
-
- #ifndef __UFAILURE__
- #include <UFailure.h>
- #endif
-
- #ifndef __QUICKDRAW__
- #include <QuickDraw.h>
- #endif
-
- #ifndef __UMACAPPUTILITIES__
- #include <UMacAppUtilities.h>
- #endif
-
- #ifndef __UERRORMGR__
- #include <UErrorMgr.h>
- #endif
-
- #ifndef __UPATCH__
- #include <UPatch.h>
- #endif
-
- #ifndef __UMACAPPGLOBALS__
- #include <UMacAppGlobals.h>
- #endif
-
- #ifndef __RESOURCES__
- #include <Resources.h>
- #endif
-
- #ifndef __TOOLUTILS__
- #include <ToolUtils.h>
- #endif
-
- #ifndef __PACKAGES__
- #include <Packages.h>
- #endif
-
- #ifndef __FOLDERS__
- #include <Folders.h>
- #endif
-
- #ifndef __ERRORS__
- #include <Errors.h>
- #endif
-
-
- #ifndef __UPROJFILEHANDLER__
- #include <UProjFileHandler.h>
- #endif
-
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- pascal void TProjFileHandler::Initialize(void) // override
- {
- inherited::Initialize();
-
- this->fProjStatus = notInProject;
- this->fWriteckid = FALSE;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAFileRes
-
- pascal void TProjFileHandler::IProjFileHandler(TFileBasedDocument* itsDocument,
- TFile* itsFile,
- const OSType itsFileType,
- const OSType itsCreator,
- Boolean usesDataFork,
- Boolean usesRsrcFork,
- Boolean keepsDataOpen,
- Boolean keepsRsrcOpen)
-
- {
- this->IFileHandler(itsDocument, itsFile, itsFileType, itsCreator, usesDataFork, usesRsrcFork, keepsDataOpen, keepsRsrcOpen);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAReadFile
-
- pascal void TProjFileHandler::DoRead(Boolean forPrinting)// override
- {
- ProjectorHandle hProj;
- short oldResFile;
-
- inherited::DoRead(forPrinting);
-
- if (this->fFile->IsRsrcForkOpen())
- {
- oldResFile = this->fFile->UseResource();
- hProj = (ProjectorHandle) Get1Resource('ckid', 128);
- if (hProj != NULL)
- {
- // found projector resource
- if ((*hProj)->checkoutState == 0)
- {
- // checked out read only
- if ((*hProj)->Modified == 0)
- this->fProjStatus = readOnly;// read only
- else
- this->fProjStatus = modReadOnly;// modify/read only
- }
- else
- this->fProjStatus = readWrite; // checked out modifiable
- }
- UseResFile(oldResFile);
- }
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAWriteFile
-
- pascal void TProjFileHandler::DoWrite(TFile* aFile,
- Boolean makingCopy)
- {
- FailInfo fi;
- Handle aHandle;
- ProjectorHandle hProj;
- long itsSize,
- sum;
- long* p;
- short oldResFile;
-
- VOLATILE(aHandle);
- VOLATILE(oldResFile);
-
- inherited::DoWrite(aFile, makingCopy);
-
- if (this->fWriteckid && aFile->IsRsrcForkOpen())
- {
- oldResFile = aFile->UseResource();
-
- if (fi.Try())
- {
- aHandle = Get1Resource('ckid', 128);
- FailNILResource(aHandle);
-
- HNoPurge(aHandle);
-
- LoadResource(aHandle);
- FailNILResource(aHandle);
-
- hProj = (ProjectorHandle) aHandle;
-
- (*hProj)->Modified = 1; // modify/read only
-
- // Recalculate the checksum so things look kosher…
- itsSize = (GetHandleSize((Handle)hProj) / sizeof(long)) - 1;
- p = &(*hProj)->locationID; // Skip the checksum field
- sum = 0;
- while (itsSize > 0)
- {
- sum = sum + *p++;
- --itsSize;
- }
-
- (*hProj)->checksum = sum;
-
- aHandle = (Handle)hProj;
-
- ChangedResource(aHandle);
- FailResError();
-
- WriteResource(aHandle);
- FailResError();
- fi.Success();
- }
- else // Recover
- {
- HPurge(aHandle);
- UseResFile(oldResFile);
- fi.ReSignal();
- }
-
- HPurge(aHandle);
- UseResFile(oldResFile);
- }
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAFileRes
-
- pascal ProjectorStatus TProjFileHandler::GetProjectorStatus(void)
- {
- return this->fProjStatus;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAFileRes
-
- pascal void TProjFileHandler::ModifyReadOnly(void)
- {
- if (this->fProjStatus == readOnly)
- {
- fProjStatus = modReadOnly;
- fWriteckid = TRUE;
- }
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAFields
-
- pascal void TProjFileHandler::Fields(TObject* obj)
- {
- obj->DoToField("TProjFileHandler", (Ptr)NULL, bClass);
- obj->DoToField("fProjStatus", (Ptr) & fProjStatus, bByte);
- obj->DoToField("fWriteckid", (Ptr) & fWriteckid, bBoolean);
-
- inherited::Fields(obj);
- }
-
-
-